package org.example.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
 * @ClassName PropertiesUtil
 * @Description: TODO
 * @Author mxzhang.ethan
 * @Date 2022/4/12
 * @Version V1.0
 **/
public class PropertiesUtil {
    public static Properties read(String classResourceName) {
        URL url = Thread.currentThread().getContextClassLoader().getResource(classResourceName);
        Properties properties = new Properties();
        if (url == null) {
            return properties;
        }
        try (InputStream inputStream = url.openStream()) {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }
    public static String read(String classResourceName,String propertyName) {
        return read(classResourceName).getProperty(propertyName);
    }
}
